﻿/**
 * http://www.kahrel.plus.com/indesign/scriptui-1-5.pdf
 */


var UI = {}

UI.create = function(win, data, name)
{
    var addObject = function(parent, param, name)
    {
        var obj = parent.add(param["type"], param["bounds"], param["text"], param["property"]);
        parent[ name ] = obj;
        
        for (var key in param) {
            var value = param[key];
            switch (key) {
                case "characters"   :
                case "selection"    :
                case "alignment"    :
                case "shortcutKey"  :
                case "orientation"  :
                    obj[key] = value;
                    break;
                    
                case "click":
                case "focus":
                case "active":
                case "change":
                    obj.addEventListener(key, value);
                    break;
                    
                case "type":
                    if (param["type"] == "panel" || param["type"] == "group") {
                        for (var c in param["child"]) {
                            addObject(obj, param["child"][c], c);
                        }
                    }
                    break;
            }
            
        }
        
        return obj;
    };
    
    addObject(win, data, name);
};


/**
 * test
 */
(function(){
    
    // return ;
    
    var sample_data = {
        "type": "panel",
        "child": {
            
            "comment-input": {
                "type": "group",
                "child": {
                    "key"   : { "type": "statictext", "text": "comment: " },
                    "input" : {
                        "type"      : "edittext",
                        "text"      : "hoge",
                        "bounds"    : [0, 0, 200, 70],
                        "property"  : { "multiline": true, "scrolling":true},
                        "alignment" : ["fill", "fill"],
                        "change"     : function(e) {  }
                    }
                }
            },

        }
    };
    
    // var myWindow = new Window("dialog", "Comment Form", undefined, {"resizeable":true} );
    // UI.create(myWindow, sample_data, "panel");
    // myWindow.show();
    
})();





